package string.easy;

import java.util.HashMap;
import java.util.Map;

public class LeetCode387 {
    public int firstUniqChar(String s) {

        Map<Character, Integer> map = new HashMap<>(s.length());

        for (int i = 0; i < s.length(); i++) {
            char a = s.charAt(i);
            map.merge(a, 1, Integer::sum);
        }

        for (int i = 0; i < s.length(); i++) {
            if (map.get(s.charAt(i)) == 1) {
                return i;
            }
        }
        return -1;
    }
}
